/*
 * Copyright (c) 18/5/25 . All Rights Reserved.
 */
package com.cgmnx.admin.web.converter.entity;

import com.cgmnx.admin.common.bean.Limiter;
import com.cgmnx.admin.dao.condition.RankNumCondition;
import com.cgmnx.admin.web.converter.Convert;
import com.cgmnx.admin.web.model.param.RankNumQueryParam;
import lombok.Data;
import org.springframework.stereotype.Component;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author: z Date: 18/5/25 Time: 下午5:09
 * @version: 1.0.0
 */
@Component

public class RankNumConditionConverter implements Convert<RankNumQueryParam, RankNumCondition> {
    @Override
    public RankNumCondition convert(RankNumQueryParam param) {

        Limiter limiter = Limiter.create(param.getPageNum(), param.getPageSize());
        Date startDate = param.getStartDate() != null ? new Date(param.getStartDate()) : null;
        Date endDate = param.getStartDate() != null ? new Date(param.getEndDate()) : null;
        return new RankNumCondition(param.getId() != null ? param.getId() : 0, param.getUserName(),
                param.getRankNum(), startDate
                , endDate, limiter);
    }

    @Override
    public List<RankNumCondition> convert(List<RankNumQueryParam> t) {
        throw new UnsupportedOperationException();
    }

    public static void main(String[] args) {
        list();
    }

    public static void list() {
        List<User> list1 = new ArrayList<>();
        List<Map<String, String>> list2 = new ArrayList<>();

        User user1 = new User();
        user1.setRealName("汪1");
        user1.setPhone("1");
        list1.add(user1);

        User user2 = new User();
        user2.setRealName("汪2");
        user2.setPhone("2");
        list1.add(user2);

        User user3 = new User();
        user3.setRealName("汪3");
        user3.setPhone("3");
        list1.add(user3);

        User user4 = new User();
        user4.setRealName("汪4");
        user4.setPhone("4");
        list1.add(user4);

        list1.stream().forEach(user -> {
            System.out.println("list1元素遍历：" + user.getRealName());
        });

        //把user的realName全部拉出来存放到list2中
        list2 = list1.stream().map(user -> {
            Map<String, String> map = new HashMap<>();
            map.put(user.getRealName(),user.phone);
            return map;
        }).collect(Collectors.toList());
        System.out.println(list2.toString());
        list2.stream().forEach(ss -> {
            System.out.println("list2遍历：" + ss);
        });
    }

}

@Data
class User {
    String realName;
    String phone;

}
